<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>短网址</title>
</head>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<body>

    请输入网址:<input type="text" name="url" id="url">

    <button type="button" onclick="fun()">确定</button><br>

    <a id="h" ></a>

</body>

<script type="text/javascript">

    var url = document.getElementById("url")

    var h = document.getElementById("h")

    function fun() {
        $.ajax({
            type:"GET",
            url:"http://127.0.0.1:8080/url/encode.do",
            data:{
                url:url.value
            },
            success:function(res){
                h.innerHTML = res

                $.ajax({
                    type:"GET",
                    url:res,
                    success:function(r){
                        h.href = r
                    }
                })

            },
            error:function(res){
            }
        })
    }



</script>

</html>